//
//  NSFormatter+shareInstance.m
//  One Night Flirt
//
//  Created by Jiang on 2017/12/18.
//  Copyright © 2017年 wudi360. All rights reserved.
//

#import "NSDateFormatter+ShareInstance.h"
@implementation NSDate (CSNSDateFormatter)
- (NSString *)stringWithFormat:(NSString *)format{
    return [NSDateFormatter stringWithFormat:format date:self];
}
@end

@implementation NSString (CSNSDateFormatter)
- (NSDate *)dateWithFormat:(NSString *)format{
    return [NSDateFormatter dateWithFormat:format string:self];
}
@end
@implementation NSDateFormatter (ShareInstance)
+ (instancetype)shareInstance{
    static NSDateFormatter *NSFormatterInstance = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        NSFormatterInstance = [[NSDateFormatter alloc]init];
        NSFormatterInstance.timeZone = [NSTimeZone timeZoneForSecondsFromGMT:0];
    });
    return NSFormatterInstance;
}
+ (NSString *)stringWithFormat:(NSString *)dateFormat date:(NSDate *)date{
    [self shareInstance].dateFormat = dateFormat;
    return [[self shareInstance] stringFromDate:date];
}

+ (NSDate *)dateWithFormat:(NSString *)format string:(NSString *)string{
    [self shareInstance].dateFormat = format;
    NSDate *date = [[self shareInstance] dateFromString:string];
    return date;
}

@end
